package eerbaar.shared.internal.tree.commands;

import java.util.List;

import eerbaar.shared.internal.tree.AbstractNode;
import eerbaar.shared.tree.INode;
import eerbaar.shared.tree.NodeIterator;

public class RemoveCmd {

    public final INode start;

    public RemoveCmd(INode start) {
        this.start = start;
    }

    public void execute(INode node) {

        NodeIterator i = new NodeIterator(this.start);
        while (i.hasNext()) {

            NodeIterator.Result r = i.next();
            INode test = r.node;
            if (test == node) {
                AbstractNode parent = (AbstractNode) i.getParent();
                parent.remove(node);
                break;
            }
        }

    }

    public void execute(List<INode> list) {
        for (INode node : list) {
            execute(node);
        }
    }

}
